<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户姓名" prop="trueName">
        <el-input
          v-model="queryParams.trueName"
          placeholder="请输入用户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
       <el-form-item label="证件类型" prop="idType">
        <el-select
          v-model="queryParams.idType"
          placeholder="证件类型"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in idTypeDict"
            :key="dict.id"
            :label="dict.name"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="角色类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="角色类型"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in typeDict"
            :key="dict.id"
            :label="dict.name"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>


      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="预约日期" prop="orderDate">
        <el-date-picker clearable
          v-model="queryParams.orderDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择预约日期">
        </el-date-picker>
      </el-form-item> -->

      <el-form-item label="预约日期" prop="orderDate">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="活动日期" prop="activityDate">
        <el-date-picker
          v-model="dateRange02"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="活动开始日期"
          end-placeholder="活动结束日期"
        ></el-date-picker>
      </el-form-item>


      <el-form-item label="活动主题" prop="activityName">
        <el-input
          v-model="queryParams.activityName"
          placeholder="请输入活动主题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="handleExport">导出</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="主键" align="center" prop="id" /> -->
      <el-table-column label="姓名" align="center" prop="trueName" />
      <el-table-column  :formatter="typeFormatter" label="角色类型" align="center" prop="type" />
      <el-table-column label="手机号" align="center" prop="mobile" />
      <!-- <el-table-column label="邮箱" align="center" prop="email" width="200" /> -->
      <el-table-column :formatter="idTypeFormatter" label="证件类型" align="center" prop="idType" />
      <el-table-column label="证件号码" align="center" prop="idNo" width="200" />
      <!-- <el-table-column label="二维码" align="center" prop="qrUrl" /> -->
      <el-table-column label="预约时间" align="center" prop="orderDate" width="180"></el-table-column>
      <!-- <el-table-column label="完成时间" align="center" prop="completeDate" width="180"></el-table-column>
      <el-table-column label="取消时间" align="center" prop="cancelDate" width="180"></el-table-column> -->
      <el-table-column label="活动主题" align="center" prop="activityName" width="180"></el-table-column>
    
      <el-table-column label="活动日期" align="center" prop="activityDate" width="180"></el-table-column>
      <el-table-column  :formatter="statusFormatter" label="状态" align="center" prop="status" />
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:detail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:detail:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    
  </div>
</template>

<script>
import { listList, getList, delList, addDetail, updateDetail,listList02 } from "@/api/system/groupDetailList";
import store from '@/store'

export default {
  name: "Detail",
  data() {
    return {
      typeDict: [
        {
          id: 1,
          name: '普通用户'
        },
        {
          id: 2,
          name: '团体机构'
        },
      ],
      idTypeDict: [
        {
          id: 1,
          name: '身份证'
        },
        {
          id: 2,
          name: '港澳通行证'
        },
        {
          id: 3,
          name: '台湾通行证'
        },
        {
          id: 4,
          name: '护照'
        },
          {
          id: 5,
          name: '外国人永居证'
        },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单（团体）领队表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      dateRange: '',
      dateRange02: '',
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        
        trueName: null,
        idType: null,
        type: null,
        mobile: null,
        email: null,
        activityName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    typeFormatter(row, column, cellValue) {
       let result = ''
      this.typeDict.map(item => {
        if(item.id == cellValue) {
          result = item.name
        }
      })
      return result
      
    },
    statusFormatter(row, column, cellValue) {
      if(cellValue == '1') {
        return '已取消'
      }
      if(cellValue == '2') {
        return '未完成'
      }
      if(cellValue == '3') {
        return '已完成'
      }
      return ''
    },
     idTypeFormatter(row, column, cellValue) {
      let result = ''
      this.idTypeDict.map(item => {
        if(item.id == cellValue) {
          result = item.name
        }
      })
      return result
    },
    /** 查询订单（团体）领队列表 */
    getList() {
      if (this.dateRange) {
        this.queryParams.startDate = this.dateRange[0] + " 00:00:00";
        this.queryParams.endDate = this.dateRange[1] + " 00:00:00";
      } else {
        this.queryParams.startDate = "";
        this.queryParams.endDate = "";
      }

      if (this.dateRange02) {
        this.queryParams.activityStartDate = this.dateRange02[0] + " 00:00:00";
        this.queryParams.activityEndDate = this.dateRange02[1] + " 00:00:00";
      } else {
        this.queryParams.activityStartDate = "";
        this.queryParams.activityEndDate = "";
      }

      this.loading = true;
      listList02(this.queryParams).then(response => {
        this.detailList = response.rows.map(item => {
          if (store.getters.isShowCard == '0' && item.idNo) {
            item.idNo = item.idNo.replace(/^(.{6})(?:\w+)(.{4})$/, "$1********$2")
            item.mobile = item.mobile.replace(/^(.{3})(?:\d+)(.{4})$/, "$1****$2")
          }
          return item
        })
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        activityOrderGroupId: null,
        trueName: null,
        idType: null,
        idNo: null,
        mobile: null,
        qrUrl: null,
        status: "0",
        completeDate: null,
        cancelDate: null,
        isDel: null,
        version: null,
        createUserId: null,
        createUserName: null,
        createTime: null,
        updateUserId: null,
        updateUserName: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = "";
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
     /** 导出按钮操作 */
     handleExport() {
      this.download('system/listGroup/export03', {
        ...this.queryParams
      }, `成员名单_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
